package cn.wolfcode.p2p.base.util;

import java.util.Calendar;
import java.util.Date;

/**
 * 获取时间间隔
 */
public class DateUtil {

    private DateUtil(){

    }
    public static long getBetweenTime(Date date1, Date date2){
        return Math.abs((date1.getTime() - date2.getTime())/1000);
    }

    /**
     * 设置一天最晚时间为23:59:59
     * @param date
     * @return
     */
    public static Date getEndDate(Date date){
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(Calendar.HOUR_OF_DAY , 23);
            calendar.set(Calendar.MINUTE , 59);
            calendar.set(Calendar.SECOND , 59);
            return calendar.getTime();
        }
        return null;
    }
}
